package com.zmn.oms.admin.controller.conf.workturn.bizmode;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dictionary.DictModel;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.model.entity.conf.workturn.bizmode.PlatBizMode;
import com.zmn.oms.model.entity.conf.workturn.bizmode.PlatBizModeQuery;
import com.zmn.oms.model.entity.conf.workturn.bizmode.log.PlatBizModeLog;
import com.zmn.oms.model.entity.conf.workturn.bizmode.log.PlatBizModeLogQuery;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 平台服务合同模式
 *
 * @author linfeng
 *
 * @since 2020/09/18 18:23
 */
@Slf4j
@Controller
@RequestMapping("/conf/workturn/bizmode/")
public class PlatBizModeListController extends PlatBizModeBaseController {

    /**
     * 平台服务合同模式详情
     * 
     * @author linfeng
     * @param query
     * @since 2020/09/18 18:22
     */
    @RequestMapping("detail")
    //@RequiresPermissions("/plat/contract/model/detail.action")
    public ModelAndView detail(@ModelAttribute PlatBizModeQuery query) {

        List<PlatBizMode> platBizTypes = platBizModeService.listAll();
        Map<Integer, PlatBizMode> map = platBizTypes.stream().collect(Collectors.toMap(o -> o.getPlat(), o -> o));
        List<DictModel> plats = GlobalConsts.getPlatList();

        List<PlatBizModeLog> logList = new ArrayList<>();
        PlatBizModeLogQuery logQuery = new PlatBizModeLogQuery();
        logQuery.setPageIndex(0);
        logQuery.setPageSize(10);
        logList = platBizModeLogService.listPageByQuery(logQuery);

        ModelAndView mav = new ModelAndView("conf/workturn/bizmode/detail");
        mav.addObject("map", map);
        mav.addObject("items", logList);
        mav.addObject("plats", plats);
        mav.addObject("contractModelList", OrderConsts.getBizModeList());

        return mav;
    }
}
